/**
 * 
 */
package org.jenkon.commons.lang.command;

import java.util.ArrayList;
import java.util.List;

import org.jenkon.commons.lang.Resetable;

/**
 * @author Jens Konopka
 * 
 */
public class CompositeCommand implements Command, Resetable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3977352391804550568L;

	private final List<Command> commands = new ArrayList<Command>();

	/**
	 * @param command
	 *            {@link Command}
	 */
	public void addCommand(final Command command) {
		this.commands.add(command);
	}

	public void addCommands(final List<Command> commands) {
		this.commands.addAll(commands);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jenkon.commons.command.Command#execute(java.lang.Object)
	 */
	@Override
	public void execute(final Object context) throws Exception {

		for (final Command command : commands) {
			command.execute(context);
		}

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jenkon.commons.Resetable#reset()
	 */
	@Override
	public void reset() {
		commands.clear();
	}

}
